import React, { Component } from 'react';
import Taro from '@tarojs/taro';
import {View} from '@tarojs/components'
import {platform} from "../../../utils/platform-settting.service";
import {user} from "../../../utils/user.service";
import {GetRequest} from "../../../utils/tools";

export default class Index extends Component {
  async UNSAFE_componentWillMount() {
    const params = Taro.getCurrentInstance().router.params
    let mpkey = ''
    const userInfo = Taro.getStorageSync('user') || ''
    if (userInfo && typeof userInfo.mpkey != "undefined") {
      mpkey = userInfo.mpkey
    }
    if (Object.keys(params).length > 0) {
      let text = '?'
      for (const key in params) {
        text += `${key}=${params[key]}&`
      }
      Taro.redirectTo({url: '/common/limited/index' + text + '&mpkey=' + mpkey})
    } else {
      if (platform.info.indexNavigation) {
        const tabbarInfo = JSON.parse(platform.info.indexNavigation)
        if (tabbarInfo.list.length > 0) {
          tabbarInfo.list.map((item, index) => {
            if (item.pagePath.indexOf('limited/index') > -1) {
              user.selected = index
            }
            return item.pagePath
          })
        }
      } else {
        const platformData = await platform.getSetting()
        if (platformData.indexNavigation) {
          const tabbarInfo = JSON.parse(platformData.indexNavigation)
          if (tabbarInfo.list.length > 0) {
            tabbarInfo.list.map((item, index) => {
              if (item.pagePath.indexOf('limited/index') > -1) {
                user.selected = index
              }
              return item.pagePath
            })
          }
        }
      }
      Taro.redirectTo({url: '/pages/limited/index'})
    }
  }

  render() {
    return (
      <View />
    )
  }
}
